using ProjectSurvivor;
using QFramework;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class PowerUp : GamePlayObject
{
    private int FlyingToPlayerFrameCount = 0;
    protected bool FlyingToPlayer { set; get; }

    protected abstract void Execute();

    private void Update()
    {
        if (FlyingToPlayer)
        {
            if (FlyingToPlayerFrameCount == 0)
            {
                GetComponent<SpriteRenderer>().sortingOrder = 5;
            }
            FlyingToPlayerFrameCount++;

            if (Player.Default)
            {
                var direction = Player.Default.Direction2DFrom(this);
                var distance = direction.magnitude;
                if (FlyingToPlayerFrameCount <= 15)
                {
                    transform.Translate(direction.normalized * -2 * Time.deltaTime);
                }
                else
                {
                    transform.Translate(direction.normalized * 7.5f * Time.deltaTime);
                }
                if (distance <= 0.1f)
                {
                    Execute();
                }
            }
        }
    }
}
